package testspring.autowired;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Service;

import testspring.autowired.iocclass.Man2;
import testspring.autowired.iocinterface.Man;

@Service
public class TestAutowired {

	/*
	 * 在Man接口前面标上@Autowired和@Qualifier注释使得Man接口可以被容器注入，
	 * 当Man接口存在两个实现类的时候必须指定其中一个来注入 ，
	 * 使用实现类首字母小写的字符串来注入。否则可以省略，只写@Autowired
	 */
	@Autowired
	@Qualifier("chinese")
	private Man man;
	
	@Autowired
	@Qualifier("chinese2")
	private Man2 man2;
	public static void main(String[] args) {
		// TODO code application logic here
		ApplicationContext ctx = new ClassPathXmlApplicationContext(
				"testspring/autowired/beans.xml");
		TestAutowired testAutowired = (TestAutowired) ctx
				.getBean("testAutowired");
		System.out.println(testAutowired.getMan().sayHello());
		System.out.println(testAutowired.getMan2().sayHello());
	}

	public Man getMan() {
		return man;
	}
	public Man2 getMan2() {
		return man2;
	}
}